<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
    
    <head>
        <meta charset="utf-8">
        <title>
            添加产品
        </title>
        <meta name="renderer" content="webkit">
        <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
        <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
        <meta name="apple-mobile-web-app-status-bar-style" content="black">
        <meta name="apple-mobile-web-app-capable" content="yes">
        <meta name="format-detection" content="telephone=no">
        <link rel="stylesheet" href="/css/x-admin.css" media="all">
    </head>
    
    <body>
        <div class="x-body">
            <form class="layui-form">
                <div class="layui-form-item">
                    <label for="link" class="layui-form-label">
                        <span class="x-red">*</span>产品图片
                    </label>
                    <div class="layui-input-inline">
                        <div class="site-demo-upbar">
                            <input type="file" name="upfile" class="layui-upload-file" id="test">
                        </div>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label for="link" class="layui-form-label">
                        <span class="x-red">*</span>图片预览
                    </label>
                    <div class="layui-input-inline" id="productImage">
                        <div class="site-demo-upbar">

                        </div>
                    </div>
                </div>

                <div class="layui-form-item">
                    <label for="imageTitle" class="layui-form-label">
                        <span class="x-red">*</span>产品名称
                    </label>
                    <div class="layui-input-inline">
                        <input type="text" id="productName" name="productName" required="" lay-verify="required"
                               autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label for="rank" class="layui-form-label">
                        <span class="x-red">*</span>供货商名称
                    </label>
                    <div class="layui-input-inline">
                        <input type="text" id="companyName" name="companyName" required="" lay-verify="required"
                               autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label for="imageLink" class="layui-form-label">
                        <span class="x-red">*</span>额度上限
                    </label>
                    <div class="layui-input-inline">
                        <input type="text" id="limitUp" name="limitUp" required="" lay-verify="required"
                               autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label for="ee" class="layui-form-label">
                        <span class="x-red">*</span>额度下限
                    </label>
                    <div class="layui-input-inline">
                        <input type="text" id="limitDown" name="limitDown" required="" lay-verify="required"
                               autocomplete="off" class="layui-input">
                    </div>
                </div>
                
                <div class="layui-form-item">
                    <label for="productParam" class="layui-form-label">
                        <span class="x-red">*</span>利率上限
                    </label>
                    <div class="layui-input-inline">
                        <input type="text" id="rateUp" name="rateUp" required="" lay-verify="required"
                        autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label for="productParam" class="layui-form-label">
                        <span class="x-red">*</span>利率下限
                    </label>
                    <div class="layui-input-inline">
                        <input type="text" id="rateDown" name="rateDown" required="" lay-verify="required"
                               autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label for="ee" class="layui-form-label">
                        <span class="x-red">*</span>产品类型
                    </label>
                    <div class="layui-input-inline">
                        <select id="productType">
                            <option value="0">API</option>
                            <option value="1">H5</option>
                            <option value="2">SDK</option>
                        </select>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label for="ee" class="layui-form-label">
                        <span class="x-red">*</span>分润方式
                    </label>
                    <div class="layui-input-inline">
                        <select id="cooperType">
                            <option value="0">CPA</option>
                            <option value="1">CPS</option>
                            <option value="2">其它</option>
                        </select>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label for="cooperRatio" class="layui-form-label">
                        <span class="x-red"></span>分润比例
                    </label>
                    <div class="layui-input-inline">
                        <input type="text" id="cooperRatio" name="cooperRatio" required=""
                               autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label for="cpaPrice" class="layui-form-label">
                        <span class="x-red"></span>利润单价(元)
                    </label>
                    <div class="layui-input-inline">
                        <input type="text" id="cpaPrice" name="cpaPrice" required=""
                               autocomplete="off" class="layui-input">
                    </div>
                </div>

                <div class="layui-form-item">
                    <label for="rebateType" class="layui-form-label">
                        <span class="x-red">*</span>返利方式
                    </label>
                    <div class="layui-input-inline">
                        <select id="rebateType">
                            <option value="0">按比例</option>
                            <option value="1">按单价</option>
                        </select>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label for="rebateRatio" class="layui-form-label">
                        <span class="x-red"></span>返利比例(%)
                    </label>
                    <div class="layui-input-inline">
                        <input type="text" id="rebateRatio" name="rebateRatio" required=""
                               autocomplete="off" class="layui-input">
                    </div>
                </div>

                <div class="layui-form-item">
                    <label for="rebatePrice" class="layui-form-label">
                        <span class="x-red"></span>返利单价(元)
                    </label>
                    <div class="layui-input-inline">
                        <input type="text" id="rebatePrice" name="rebatePrice" required=""
                               autocomplete="off" class="layui-input">
                    </div>
                </div>

                <div class="layui-form-item">
                    <label for="productIntroduce" class="layui-form-label">
                        <span class="x-red"></span>产品介绍
                    </label>
                    <div class="layui-input-inline">
                        <textarea name="productIntroduce" id="productIntroduce"></textarea>
                    </div>
                </div>

                <div class="layui-form-item">
                    <label for="productUrl" class="layui-form-label">
                        <span class="x-red">*</span>跳转地址
                    </label>
                    <div class="layui-input-inline">
                        <input type="text" id="productUrl" name="productUrl" required="" lay-verify="required"
                               autocomplete="off" class="layui-input">
                    </div>
                </div>

                <div class="layui-form-item">
                    <label for="productRank" class="layui-form-label">
                        <span class="x-red"></span>排列顺序
                    </label>
                    <div class="layui-input-inline">
                        <input type="text" id="productRank" name="productRank" required=""
                               autocomplete="off" class="layui-input">
                    </div>
                </div>

                <div class="layui-form-item">
                    <label for="productLable1" class="layui-form-label">
                        <span class="x-red"></span>产品标签1
                    </label>
                    <div class="layui-input-inline">
                        <input type="text" id="productLable1" name="productLable1" required=""
                               autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label for="productLable2" class="layui-form-label">
                        <span class="x-red"></span>产品标签2
                    </label>
                    <div class="layui-input-inline">
                        <input type="text" id="productLable2" name="productLable2" required=""
                               autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label for="productLable3" class="layui-form-label">
                        <span class="x-red"></span>产品标签3
                    </label>
                    <div class="layui-input-inline">
                        <input type="text" id="productLable3" name="productLable3" required=""
                               autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label for="productLable4" class="layui-form-label">
                        <span class="x-red"></span>产品标签4
                    </label>
                    <div class="layui-input-inline">
                        <input type="text" id="productLable4" name="productLable4" required=""
                               autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label for="productLable5" class="layui-form-label">
                        <span class="x-red"></span>产品标签5
                    </label>
                    <div class="layui-input-inline">
                        <input type="text" id="productLable5" name="productLable5" required=""
                               autocomplete="off" class="layui-input">
                    </div>
                </div>

                <div class="layui-form-item">
                    <label for="productDeadline" class="layui-form-label">
                        <span class="x-red">*</span>过期时间
                    </label>
                    <div class="layui-input-inline">
                        <input type="text" id="productDeadline" name="productDeadline" required="" lay-verify="required"
                               autocomplete="off" class="layui-input" placeholder="2000-09-09">
                    </div>
                </div>

                <div class="layui-form-item">
                    <label for="applyConditions" class="layui-form-label">
                        <span class="x-red"></span>申请条件
                    </label>
                    <div class="layui-input-inline">
                        <input type="text" id="applyConditions" name="applyConditions" required=""
                               autocomplete="off" class="layui-input" placeholder="每个条件之间用|隔开">
                    </div>
                </div>



                <div class="layui-form-item">
                    <label for="responseType" class="layui-form-label">
                        <span class="x-red">*</span>数据返回
                    </label>
                    <div class="layui-input-inline">
                        <select id="responseType">
                            <option value="0">线上返回</option>
                            <option value="1">手工返回</option>
                            <option value="2">不返回</option>
                        </select>
                    </div>
                </div>

                <div class="layui-form-item">
                    <label for="hotProductFlag" class="layui-form-label">
                        <span class="x-red">*</span>热度标识
                    </label>
                    <div class="layui-input-inline">
                        <select id="hotProductFlag">
                            <option value="1">显示</option>
                            <option value="0">不显示</option>
                        </select>
                    </div>
                </div>

                <div class="layui-form-item">
                    <label for="selectedProductFlag" class="layui-form-label">
                        <span class="x-red">*</span>精品标识
                    </label>
                    <div class="layui-input-inline">
                        <select id="selectedProductFlag">
                            <option value="1">显示</option>
                            <option value="0">不显示</option>
                        </select>
                    </div>
                </div>

                <div class="layui-form-item">
                    <label for="selectedProductFlag" class="layui-form-label">
                        <span class="x-red">*</span>产品特性
                    </label>
                    <div class="layui-input-inline">
                        <input type="checkbox" name="productFeature" value="1">易通过
                        <input type="checkbox" name="productFeature" value="2">额度高
                        <input type="checkbox" name="productFeature" value="3">返利高
                        <input type="checkbox" name="productFeature" value="4">利息低
                        <input type="checkbox" name="productFeature" value="5">还信用卡
                        <input type="checkbox" name="productFeature" value="6">下款快
                        <input type="checkbox" name="productFeature" value="0">其它
                    </div>
                </div>

                <div class="layui-form-item">
                    <label for="stagesRange" class="layui-form-label">
                        <span class="x-red"></span>期限范围
                    </label>
                    <div class="layui-input-inline">
                        <input type="text" id="stagesRange" name="stagesRange" required=""
                               autocomplete="off" class="layui-input" placeholder="1-12期">
                    </div>
                </div>


                <div class="layui-form-item">
                    <label for="L_repass" class="layui-form-label">
                    </label>
                    <button  class="layui-btn" lay-filter="add" lay-submit="">
                        增加
                    </button>
                </div>
            </form>
        </div>
        <script src="/lib/layui/layui.js" charset="utf-8">
        </script>
        <script src="/js/x-layui.js" charset="utf-8">
        </script>
        <script>
            var imageFilename = '';
            layui.use(['form','layer', 'upload'], function(){
                $ = layui.jquery;
              var form = layui.form();
              var layer = layui.layer;

                layui.upload({
                    url: '/product/upload.html', //上传接口
                    success: function(res){ //上传成功后的回调
                        imageFilename = res.data.filename;
                        //<img src="" id="productImage" width="60px" height="40px">
                        $('#productImage').html('<img src="'+ res.data.imageUrl +'" width="100px" height="40px">');
                    }
                });

                var featurePro = [];
              //监听提交
              form.on('submit(add)', function(data){

                  $('input[name="productFeature"]:checked').each(function(){
                      featurePro.push($(this).val());
                  });

                //发异步，把数据提交给服务器
                  $.ajax({
                      url: '/product/add.html',
                      type: 'POST', //GET
                      async: true,    //或false,是否异步
                      data: {
                          productName : $('#productName').val(),
                          companyName : $('#companyName').val(),
                          limitUp : $('#limitUp').val(),
                          limitDown : $('#limitDown').val(),
                          rateUp : $('#rateUp').val(),
                          rateDown : $('#rateDown').val(),
                          productType : $('#productType').val(),
                          cooperType : $('#cooperType').val(),
                          cooperRatio : $('#cooperRatio').val(),
                          cpaPrice : $('#cpaPrice').val(),
                          rebateType : $('#rebateType').val(),
                          rebateRatio : $('#rebateRatio').val(),
                          rebatePrice : $('#rebatePrice').val(),
                          productIntroduce : $('#productIntroduce').val(),
                          productRank : $('#productRank').val(),
                          productLable1 : $('#productLable1').val(),
                          productLable2 : $('#productLable2').val(),
                          productLable3 : $('#productLable3').val(),
                          productLable4 : $('#productLable4').val(),
                          productLable5 : $('#productLable5').val(),
                          deadTime : $('#productDeadline').val(),
                          applyConditions : $('#applyConditions').val(),
                          responseType : $('#responseType').val(),
                          hotProductFlag : $('#hotProductFlag').val(),
                          selectedProductFlag : $('#selectedProductFlag').val(),
                          productUrl : $('#productUrl').val(),
                          productLogo : imageFilename,
                          productFeature : featurePro.join("-"),
                          stagesRange : $('#stagesRange').val()
                      },
                      timeout: 10000,    //超时时间
                      dataType: 'json',    //返回的数据格式：json/xml/html/script/jsonp/text
                      success: function (ajaxData, textStatus, jqXHR) {
                          if (!ajaxData.success) {
                              alert(ajaxData.message);
                              layer.alert(ajaxData.message, {icon: 6},function () {});
                              return;
                          }

                          layer.alert("增加成功", {icon: 6}, function () {
                              location.reload();
                          });

                      }
                  });
                return false;
              });
            });
        </script>
        <script>

        </script>
    </body>

</html>